package kbs.scm
{
    public class InstanceMethodFunction extends PrimitiveFunction
    {
        public function InstanceMethodFunction(mname:String)
        {
            m_mname = mname;
        }

        override public function scmapply(alist:AList, env:Env):Base
        {
            var argc:int = alist.length();
            if (argc == 0) {
                throw new Error("instance method -- missing object to apply "+m_mname);
            }
            var inst:Object = toObject(alist.get(0), env);

            var a:Array = [];
            for (var i:int = 1; i<argc; i++) {
                a.push(toObject(alist.get(i), env));
            }

            var myret:Object = inst[m_mname].apply(env, a);
            return toBase(myret);
        }

        override public function pprint():String
        {
            return "."+m_mname;
        }
        private var m_mname:String;
    }
}
